
<template>
  <el-dialog :title="addParams.deitInfo!=undefined?'修改':'添加'" :visible.sync="zdTreeDeitOpen" width="30%"  append-to-body
      :before-close="closeDelDialog">
    <el-form ref="treeForm" :model="treeForm" :rules="treeRules" label-width="100px">
      <el-form-item label="条款" prop="name">
        <el-input v-model="treeForm.name" placeholder="请输入名称" maxlength="30" />
      </el-form-item>
      <el-form-item label="保管期限" prop="bgqx">
        <el-select v-model="treeForm.bgqx" placeholder="请选择保管期限" style="width: 100%" class="el-selectTree">
          <el-option v-for="item in storeModeOption" :key="item.dictValue" :label="item.dictLabel"
            :value="item.dictValue"></el-option>
        </el-select>
      </el-form-item>


      <el-form-item label="排序" prop="orderNo">
        <el-input-number style="width: 100%" v-model="treeForm.orderNo" controls-position="right" placeholder="请输入排序"
          :min="1" :max="500"></el-input-number>
      </el-form-item>

      <el-form-item label="备注" prop="remark">
        <el-input v-model="treeForm.remark" type="textarea" style="width: 100%" placeholder="请输入内容"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitTrreForm">保 存</el-button>
      <el-button @click="closeDelDialog">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { addzd2,gdfwandbgqxEditzd2,getzd2} from "@/api/manage/archivesCategory";
import {addzd,gdfwandbgqxEditzd,getzd} from "@/api/archive/archivesCategory.js";
export default {
  dicts: ['sys_normal_disable', 'basic_data_fieldtype'],
  // cateIsType  0=应用定义档案门类里面的元数据方案明细列表添加    1=应用定义里面的元数据方案明细列表添加  2=立档单位下面的模板管理的元数据方案添加
  watch: {
    addParams: {
            deep: true,
            immediate: true, // 监听到后，立即执行 handler方法
            handler: function (newVal, oldVal) {
              console.log(newVal,"000")
              this.treeForm.groupId = newVal.queryAddParams.groupId;
              this.treeForm.type = newVal.queryAddParams.type;
              this.treeForm.categoryId = newVal.queryAddParams.categoryId;
              this.cateIsType = newVal.cateIsType;
                if(newVal.deitInfo!=undefined){ //修改
                  if (this.cateIsType == "0" || this.cateIsType == "1") {
                  getzd(newVal.deitInfo.id).then(res=>{
                     
                      if(res.code=="200"){
                        this.treeForm.orderNo=res.data.orderNo;
                        this.treeForm.remark=res.data.remark;
                        this.treeForm.bgqx=res.data.bgqx;
                        this.treeForm.name=res.data.name;
                      }
                      console.log(this.treeForm,"---")
                  })
                }else{
                  getzd2(newVal.deitInfo.id).then(res=>{
                     
                     if(res.code=="200"){
                       this.treeForm.orderNo=res.data.orderNo;
                       this.treeForm.remark=res.data.remark;
                       this.treeForm.bgqx=res.data.bgqx;
                       this.treeForm.name=res.data.name;
                     }
                     console.log(this.treeForm,"---")
                 })
                  }
                }else{ //添加
                this.treeForm.parentId=newVal.parentId;
                }
            },

        }
  },
  props: ['zdTreeDeitOpen', 'addParams'],
  data() {
    return {
      storeModeOption:[],//保管期限列表
      treeForm: {
        name: undefined, //条款
        parentId: undefined,
        orderNo: undefined, //序号
        remark: undefined, //备注
        bgqx: undefined,//保管期限
        categoryId: undefined //门类
      },
      treeRules: {
        name: [
          { required: true, message: '请输入名称', trigger: 'blur' },
        ],
        bgqx: [
          { required: true, message: '请选择保管期限', trigger: 'change' }
        ],
        orderNo: [
            { required: true, message: '请输入序号', trigger: 'blur' },
          ],
      }
    }
  },
  created(){
  
    if (this.cateIsType == "0" || this.cateIsType == "1") {
      this.getDicts_archive("BGQX").then(res=>{
        this.storeModeOption=res.data
      })
    }else{
      this.getDicts_user("BGQX").then(res=>{
        this.storeModeOption=res.data
      })
    } 
  },
  methods: {

    //保存
    submitTrreForm() {
      if(this.addParams.deitInfo!=undefined){
        this.treeForm["isDel"]=0;
        this.treeForm["id"]=this.addParams.deitInfo.id;
        this.$refs["treeForm"].validate((valid) => {
          if (valid) {
            if (this.cateIsType == "0" || this.cateIsType == "1") {
              gdfwandbgqxEditzd(this.treeForm).then(res=>{
              if(res.code=="200"){
                this.$modal.msgSuccess("修改成功");
                this.$emit("submitzdTrreForm")
              }
            })
            }else{
              gdfwandbgqxEditzd2(this.treeForm).then(res=>{
              if(res.code=="200"){
                this.$modal.msgSuccess("修改成功");
                this.$emit("submitzdTrreForm")
              }
            })
            }
           
          } else {
            console.log('error submit!!');
            return false;
          }
        });

      }else{
        this.$refs["treeForm"].validate((valid) => {
          if (valid) {
            if (this.cateIsType == "0" || this.cateIsType == "1") {
              addzd(this.treeForm).then(res=>{
              if(res.code=="200"){
                this.$modal.msgSuccess("添加成功");
                this.$emit("submitzdTrreForm")
              }
            })
            }else{
              addzd2(this.treeForm).then(res=>{
              if(res.code=="200"){
                this.$modal.msgSuccess("添加成功");
                this.$emit("submitzdTrreForm")
              }
            })
            }
           
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
      
    },


    closeDelDialog() {
      this.$emit("closezdTreeDeitDialog")
    }

  }
}

</script>
<style lang="scss" scoped>
// ::v-deep .el-dialog {
//     display: flex;
//     flex-direction: column;
//     margin: 0 !important;
//     position: absolute;
//     top: 50%;
//     left: 50%;
//     transform: translate(-50%, -50%);
//     max-height: calc(100% - 30px);
//     max-width: calc(100% - 30px);
// }

// ::v-deep .el-dialog .el-dialog__body {
//     flex: 1;
//     overflow: auto;
// }
</style>


